package cate.game.play.skill.passive.exp;

import cate.common.table.d.GDBuff;
import cate.game.play.buff.Buff;
import cate.game.play.buff.h.护盾BH;
import cate.game.play.config.PlayCfgArgs;
import cate.game.play.proce.action.ctx.ActionCtx;
import cate.game.play.skill.passive.PassiveHandler;

/**
 * 自身携带护盾时，临时获得15%的伤害减免
 */
public class 可靠防护PH extends PassiveHandler {

	private int buff;

	//buff=？？
	@Override
	public void parse(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		buff = args.getInt("buff", 0);
	}

	private boolean add;

	@Override
	public void onOwnerAddBuff(ActionCtx action, Buff addBuff) {
		if (add) {
			return;
		}
		if (addBuff.handler instanceof 护盾BH) {
			add = true;
			skill.owner.buff.tryAddByTid(action, buff);
		}
	}



	@Override
	public void onOwnerBuffInvalid(ActionCtx action, byte invalidReason, Buff otherBuff) {
		if (!add) {
			return;
		}
		if (!(otherBuff.handler instanceof 护盾BH)) {
			return;
		}
		if(skill.owner.buff.containType(GDBuff.Type.SHIELD_TYPES)){
			return;
		}
		add = false;
		skill.owner.buff.removeBuffByTid(action, buff);
	}
}
